<template>
  <views class="agent_withdraw_list">
    <viewTitle :title="'提现申请'" :border="false"></viewTitle>
    <!-- 搜索列表 -->
    <el-form ref="form" label-width="auto" :inline="true">
      <div class="search_input flex flexR center">
        <div class="their_facilitator flex flexR center">
          <el-form-item label="选择代理商:">
            <el-select v-model="agent_status" clearable placeholder="请选择">
              <el-option
                v-for="item in agent_status_list"
                :key="item.agent_id"
                :label="item.agent_name"
                :value="item.agent_id"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>

        <div class="pay_time flex flexR center">
          <el-form-item label="提交时间:">
            <el-date-picker
              v-model="apply_time"
              type="datetimerange"
              align="right"
              :default-time="['0:00:00','23:59:59']"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
        </div>

        <div class="pay_state flex flexR center">
          <el-form-item label="状态:">
            <el-select v-model="status" clearable placeholder="请选择">
              <el-option
                v-for="item in status_list"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <el-form-item>
          <div class="flex flexR pay_btn_list">
            <el-button type="primary" @click="query">查看</el-button>
            <el-button @click="reset">重置</el-button>
          </div>
        </el-form-item>
      </div>
    </el-form>
    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        max-height="450"
      >
        <el-table-column fixed="left" type="index" label="序号" width="100"></el-table-column>
        <el-table-column prop="agent_name" label="代理商名称" width="200"></el-table-column>
        <el-table-column prop="agent_sn" label="代理商编号" width="200"></el-table-column>
        <el-table-column prop="money" label="提现金额" width="auto"></el-table-column>
        <el-table-column prop="created_time" label="申请时间" width="200"></el-table-column>
        <!-- <el-table-column prop="contact_name" label="申请姓名" width="120"></el-table-column> -->
        <el-table-column prop="status_desc" label="状态" width="100"></el-table-column>
        <el-table-column label="操作" width="250">
          <template slot-scope="scope" class="table_operation flex flexR">
            <el-button type="warning" v-if="scope.row.status==0" @click="check(scope)">审核</el-button>
            <el-button type="danger" v-if="scope.row.status==0" @click="refuse(scope)">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="handleSizeChange($event)"
          @current-change="changePage($event)"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>


<script>
export default {
  name: "",
  data() {
    return {
      agent_status_list: [],
      agent_status: "",
      status_list: [
        {
          label: "全部",
          value: ""
        },
        {
          label: "申请中",
          value: 0
        },
        {
          label: "通过",
          value: 1
        },
        {
          label: "拒绝",
          value: 2
        }
      ], // 状态列表
      status: "", // 状态
      apply_time: "", // 申请时间
      from_time: "", // 开始时间
      end_time: "", // 结束时间
      tableData: [],
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      }
    };
  },
  watch: {
    apply_time: function(val) {
      this.from_time = val[0]/1000;
      this.end_time = val[1]/1000;
    }
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    handleSizeChange(page_size) {
      //变动每页数量时
      this.pagination.page_size = page_size;
      this.query();
    },
    changePage(current_page) {
      //切换页码时
      this.pagination.page_start = current_page;
      this.query();
    },
    getAgentData() {
      let { code, msg, data } = this.$api.sendSync(
        this.$mapapi.f_getAgentList,
        {
          status: 1,
          pagination: {
            page_start: 1,
            page_size: 999
          }
        }
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        this.agent_status_list = [];
        return;
      }
      this.agent_status_list = data.list || [];
    },
    // 查看
    query() {
      let data = this.$api.sendSync(this.$mapapi.f_withdrawList, {
        agent_id: this.agent_status,
        status: this.status,
        from_time: this.from_time,
        end_time: this.end_time,
        pagination: this.pagination
      });
      this.tableData = data.data.list || [];
      this.pagination = data.data.pagination;
    },
    // 重置
    reset() {
      this.status = ""; // 状态
      this.apply_time = ""; // 申请时间
      this.from_time = ""; // 开始时间
      this.end_time = ""; // 结束时间
      this.agent_status = "";
    },
    // 修改状态
    f_changeWithdrawStatus(id, status) {
      let data = this.$api.sendSync(this.$mapapi.f_changeWithdrawStatus, {
        agent_withdraw_log_id: id,
        status: status
      });
      if (data.code == 200) {
        this.$message({
          type: "success",
          message: "审核成功"
        });
        this.query();
      } else {
        this.$message({
          type: "error",
          message: data.msg
        });
      }
      console.log("mmmmmmmm", data);
    },
    // 审核
    check(row) {
      let { agent_withdraw_log_id, agent_name } = row.row || {},
        that = this;
      this.$confirm(`此操作将审核-${agent_name}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(r => {
          that.f_changeWithdrawStatus(agent_withdraw_log_id, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 拒绝
    refuse(row) {
      let { agent_withdraw_log_id, agent_name } = row.row || {},
        that = this;
      this.$confirm(`此操作将拒绝-${agent_name}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(r => {
          that.f_changeWithdrawStatus(agent_withdraw_log_id, 2);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    }
  },
  created() {},
  mounted() {
    this.getAgentData();
    this.query();
  }
};
</script>

<style lang="less" scope="true"   src="@/style/agentManagements/agent_withdraw_list.less" >
</style>